package com.teach.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teach.mapper.CourseMapper;
import com.teach.mapper.TimetableMapper;
import com.teach.pojo.Course;
import com.teach.pojo.RespBean;
import com.teach.pojo.Timetable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TimetableServiceImpl extends ServiceImpl<TimetableMapper, Timetable> implements TimetableService{
    @Autowired
    private TimetableMapper timetableMapper;
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public RespBean getTables(Long classId) {
        List<Timetable> tables = timetableMapper.selectList(new QueryWrapper<Timetable>().eq("class_id", classId));
        List<String> week1 = new ArrayList<>();
        List<String> week2 = new ArrayList<>();
        List<String> week3 = new ArrayList<>();
        List<String> week4 = new ArrayList<>();
        List<String> week5 = new ArrayList<>();
        tables.forEach(item->{
            Course course = courseMapper.selectOne(new QueryWrapper<Course>().eq("id", item.getCourseId()));
            switch (item.getWeek()){
                case 1:
                    week1.add(course.getCourseName());
                    break;
                case 2:
                    week2.add(course.getCourseName());
                    break;
                case 3:
                    week3.add(course.getCourseName());
                    break;
                case 4:
                    week4.add(course.getCourseName());
                    break;
                case 5:
                    week5.add(course.getCourseName());
                    break;
            }
        });
        List<List> weeks = new ArrayList<>();
        weeks.add(week1);
        weeks.add(week2);
        weeks.add(week3);
        weeks.add(week4);
        weeks.add(week5);
        return RespBean.success(weeks);
    }
}
